﻿using Autofac;
using PMS.Core.Configuration.CommonEnumConfigs;
using PMS.Data.Entities.Settings;

namespace PMS.Services.EntityServices.Medias
{
    public class MediaServiceProvider : IMediaProvider
    {
        #region Fields
        private readonly MediaSettings _mediaSettings;
        private readonly IComponentContext _componentContext;//Autofac上下文
        #endregion

        #region Ctor
        public MediaServiceProvider(MediaSettings mediaSettings,
            IComponentContext componentContext)
        {
            _mediaSettings = mediaSettings;
            _componentContext = componentContext;
        }
        #endregion

        #region Utils
        private IMediaFileService GetMediaServiceFromStoreMode()
        {
            return _mediaSettings.StoreMode switch
            {
                MediaFileStoreMode.LocalFile => _componentContext.ResolveNamed<IMediaFileService>(typeof(MediaFileLocalService).Name),
                MediaFileStoreMode.QingStor => _componentContext.ResolveNamed<IMediaFileService>(typeof(MediaFileQingStorService).Name),
                _ => null
            };
        }
        #endregion

        #region Properties
        public IMediaFileService MediaService { get => GetMediaServiceFromStoreMode(); }
        #endregion
    }
}
